package com.extension.company.view.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.extension.company.admin.R;
import com.extension.company.model.entity.RightListBean;
import com.extension.company.common.widget.ShapedImageView;
import com.extension.company.model.api.RetrofitUrlApi;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MakeMoneyRightAdapter extends RecyclerView.Adapter<MakeMoneyRightAdapter.RightHolder> {


	private Context context;
	private List<RightListBean.DataBean.GoodsBean> list;

	public MakeMoneyRightAdapter(Context context, List<RightListBean.DataBean.GoodsBean> list) {
		this.context = context;
		this.list = list;
	}

	@NonNull
	@Override
	public RightHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
//		View view = LayoutInflater.from(context).inflate(R.layout.fragment_moneyright_item, viewGroup, false);
		View view = LayoutInflater.from(context).inflate(R.layout.fragment_location_city_list_item, viewGroup, false);

		return new RightHolder(view);
	}

	@Override
	public void onBindViewHolder(@NonNull RightHolder rightHolder, int i) {
		RequestOptions requestOptions = new RequestOptions()
				.placeholder(R.mipmap.ic_launcher)
				.error(R.mipmap.ic_launcher)
				.centerCrop()
				.transform(new RoundedCorners(15));
		Glide.with(context)
				.load(RetrofitUrlApi.BaseHostUrl + list.get(i).getImage())
				.apply(requestOptions)
				.into(rightHolder.classifyRightItemImg);

		rightHolder.classifyRightItemGet.setText(list.get(i).getShare_percent());
		rightHolder.classifyRightItemPrice.setText(list.get(i).getGoods_price());
		rightHolder.classifyRightItemTitle.setText(list.get(i).getGoods_name());


	}

	@Override
	public int getItemCount() {
		return list.size();
	}

//    private Context context;
//
//    public MakeMoneyRightAdapter(Context context) {
//        this.context = context;
//    }
//
//    @Override
//    public int getCount() {
//        return 10;
//    }
//
//    @Override
//    public Object getItem(int position) {
//        return null;
//    }
//
//    @Override
//    public long getItemId(int position) {
//        return 0;
//    }
//
//    @Override
//    public View getView(int position, View convertView, ViewGroup parent) {
//        if (convertView == null) {
//            convertView = LayoutInflater.from(context).inflate(R.layout.fragment_moneyright_item, null);
//        }
//        return convertView;
//    }


	class RightHolder extends RecyclerView.ViewHolder {
		@BindView(R.id.classify_right_item_img)
		ShapedImageView classifyRightItemImg;
		@BindView(R.id.classify_right_item_title)
		TextView classifyRightItemTitle;
		@BindView(R.id.classify_right_item_get)
		TextView classifyRightItemGet;
		@BindView(R.id.classify_right_item_price)
		TextView classifyRightItemPrice;

		RightHolder(@NonNull View itemView) {
			super(itemView);
			ButterKnife.bind(this, itemView);
		}
	}

	public interface rightClassfy {
		void righClick(int position);
	}

	private rightClassfy rightClassfy;

	public void setOnRightItemClick(rightClassfy rightClassfy) {
		this.rightClassfy = rightClassfy;
	}


}
